========================================================================= 
Log Path: output/log/log_A_CCMLinkingTable.log 
Program Path: /Users/wenhao/Dropbox/Research/Inverted Liquidity Crises/Data/Firm quality and financial availability - Wenhao's version/code/0_DownloadData/1_CCMLinkingTable.R 
Working Directory: /Users/wenhao/Dropbox/Research/Inverted Liquidity Crises/Data/Firm quality and financial availability - Wenhao's version 
User Name: wenhao 
R Version: 4.4.0 (2024-04-24) 
Machine: Wenhaos-MacBook-2020.local x86_64 
Operating System: Darwin 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:31 PST 2024; root:xnu-10063.101.15~2/RELEASE_X86_64 
Base Packages: stats graphics grDevices utils datasets methods base 
Other Packages: tidylog_1.1.0 RPostgres_1.4.7 procs_1.0.6 reporter_1.4.4 libr_1.3.3 logr_1.3.8 fmtr_1.6.5 common_1.1.3 sassy_1.2.5 DescTools_0.99.54 here_1.0.1 data.table_1.15.4 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.1 tidyverse_2.0.0 stargazer_5.2.3 lfe_3.0-0 Matrix_1.7-0 
Log Start Time: 2024-07-08 17:12:04.506674 
========================================================================= 

> library(tidyverse)
> library(data.table)
> library(here)
> library(sassy)
> library(RPostgres)
> setwd(dirname(rstudioapi::getActiveDocumentContext()$path)); 
> setwd("../../")
> 
> # Open the log
> lf <- log_open("output/log/log_A_CCMLinkingTable.log", autolog = T, show_notes = F)
> 
> 
> # Send code to the log
> log_code()
> 
> # 1 Read data from WRDS -------------------------------------------------------------------
> sep("1 Read data from WRDS")
> 
> 
> wrds <- dbConnect(Postgres(),
>                   host='wrds-pgdata.wharton.upenn.edu',
>                   port=9737,
>                   dbname='wrds',
>                   sslmode='require',
>                   user='wenhao19')
> 
> SQL_statement <- 
>   "
>   SELECT a.gvkey, a.cik, a.sic, a.naics, b.linkprim, 
>           b.linktype, b.liid, b.lpermno as permno, b.lpermco as permco,
>           b.linkdt as timeLinkStart_d, b.linkenddt as timeLinkEnd_d
>   FROM comp.names as a
>   INNER JOIN crsp.ccmxpf_lnkhist as b
>     ON a.gvkey = b.gvkey
>   WHERE b.linktype in ('LC', 'LU')
>   AND b.linkprim in ('P', 'C')
>   ORDER BY a.gvkey
> "
> 
> res <- dbSendQuery(conn = wrds, statement = SQL_statement)
> df_CCMLinkingTable <- dbFetch(res)
> dbClearResult(res)
> 
> # save
> fwrite(df_CCMLinkingTable, here("data", "Link", "CCMLinkingTable.csv"))
> saveRDS(df_CCMLinkingTable, here("data", "Link", "CCMLinkingTable.RDS"))
> 
> 
> # Close log
> log_close()
> 
> # View results
> writeLines(readLines(lf))

========================================================================= 
1 Read data from WRDS 
========================================================================= 

Error in fwrite(df_CCMLinkingTable, here("data", "Link", "CCMLinkingTable.csv")) : No such file or directory: '/Users/wenhao/Dropbox/Research/Inverted Liquidity Crises/Data/Firm quality and financial availability - Wenhao's version/code/data/Link/CCMLinkingTable.csv'. Unable to create new file for writing (it does not exist already). Do you have permission to write here, is there space on the disk and does the path exist? 
Traceback: 
1: fwrite(df_CCMLinkingTable, here("data", "Link", "CCMLinkingTable.csv")) 

========================================================================= 
Log End Time: 2024-07-08 17:12:10.814442 
Log Elapsed Time: 0 00:00:06 
========================================================================= 
